package com.mylib.libcore.utils;

import android.text.TextUtils;


import com.mylib.libcore.AppContext;
import com.mylib.libcore.utils.simplecache.ACache;

import java.io.Serializable;
import java.util.List;

import static com.mylib.libcore.utils.simplecache.ACache.TIME_DAY;


/**
 * 存取缓存的工具，存取一起出现
 */

public class ACacheUtil {


    public static void saveYijiData(){
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        mCache.put("yijiData", "1",30*TIME_DAY);
    }
    public static String getYijiData(){
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        return mCache.getAsString("yijiData");
    }
    public static void saveShenShaData(){
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        mCache.put("shenShaData", "1",30*TIME_DAY);
    }
    public static String getShenShaData(){
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        return mCache.getAsString("shenShaData");
    }

    public static void saveKey(String key,String vaue) {
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        mCache.put(key+"", vaue+"");
    }

    public static String getKey(String key) {
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        return mCache.getAsString(key+"");
    }

    public static void saveKeyTime(String key,String vaue,int time) {
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        mCache.put(key+"", vaue+"",time);
    }

    public static String getKeyTime(String key) {
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        return mCache.getAsString(key+"");
    }


    public static void saveKeyTimeMouth(String key,String vaue) {
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        mCache.put(key+"", vaue+"",30*24*60*60);//一个月
    }

    public static String getKeyTimeMouth(String key) {
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        return mCache.getAsString(key+"");
    }



    public static void saveCity(List<String> cityList) {
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        mCache.put("testCity", cityList);
    }

    public static List<String> getCityList() {
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        return mCache.getList("testCity");
    }


    /**
     * 获取日出时间
     * 默认为 6:30
     *
     * @return
     */
    public static String getSunupTime() {
        String sunupTime;
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        if (TextUtils.isEmpty(mCache.getAsString("sunupTime"))) {
            sunupTime = "06:30";
        } else {
            sunupTime = mCache.getAsString("sunupTime");
        }
        return sunupTime;
    }

    /**
     * 获得日落时间
     *
     * @return
     */
    public static String getSunsetTime() {
        String sunupTime;
        ACache mCache = ACache.get(AppContext.getInstance().getContext());
        if (TextUtils.isEmpty(mCache.getAsString("sunsetTime"))) {//默认
            sunupTime = "18:30";
        } else {
            sunupTime = mCache.getAsString("sunsetTime");
        }
        return sunupTime;
    }
}
